import React from 'react';
import { Tree } from 'antd';
import _ from 'lodash';

class MyTree extends React.Component {
    constructor(props) {
        super(props);

        this.onSelect = this.onSelect.bind(this);

        this.clickCount = 0;
        this.handleDoubleClick = _.debounce((node) => {
            // console.log('handleDoubleClick', this);
            const count = this.clickCount;
            this.clickCount = 0;

            if (count >= 2) {
                // it's doubleclick
                this.props.onDoubleClick && this.props.onDoubleClick(node);
            }
        }, 300);
    }

    onSelect(selectedKeysValue, info) {
        const node = info.node;
        this.props.onSelect && this.props.onSelect(selectedKeysValue, info);

        this.clickCount += 1;
        this.handleDoubleClick(node);
    }

    render() {
        return (
            <Tree {...this.props} onSelect={this.onSelect} />
        );
    }
}

export default MyTree